﻿using System;

namespace UniRx.Operators
{
	// Token: 0x020002BD RID: 701
	internal class MaterializeObservable<T> : OperatorObservableBase<Notification<T>>
	{
		// Token: 0x06000F2E RID: 3886 RVA: 0x00046B3C File Offset: 0x00044F3C
		public MaterializeObservable(IObservable<T> source) : base(source.IsRequiredSubscribeOnCurrentThread<T>())
		{
			this.source = source;
		}

		// Token: 0x06000F2F RID: 3887 RVA: 0x00046B51 File Offset: 0x00044F51
		protected override IDisposable SubscribeCore(IObserver<Notification<T>> observer, IDisposable cancel)
		{
			return new MaterializeObservable<T>.Materialize(this, observer, cancel).Run();
		}

		// Token: 0x040008D8 RID: 2264
		private readonly IObservable<T> source;

		// Token: 0x020002BE RID: 702
		private class Materialize : OperatorObserverBase<T, Notification<T>>
		{
			// Token: 0x06000F30 RID: 3888 RVA: 0x00046B60 File Offset: 0x00044F60
			public Materialize(MaterializeObservable<T> parent, IObserver<Notification<T>> observer, IDisposable cancel) : base(observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x06000F31 RID: 3889 RVA: 0x00046B71 File Offset: 0x00044F71
			public IDisposable Run()
			{
				return this.parent.source.Subscribe(this);
			}

			// Token: 0x06000F32 RID: 3890 RVA: 0x00046B84 File Offset: 0x00044F84
			public override void OnNext(T value)
			{
				this.observer.OnNext(Notification.CreateOnNext<T>(value));
			}

			// Token: 0x06000F33 RID: 3891 RVA: 0x00046B9C File Offset: 0x00044F9C
			public override void OnError(Exception error)
			{
				this.observer.OnNext(Notification.CreateOnError<T>(error));
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000F34 RID: 3892 RVA: 0x00046BE8 File Offset: 0x00044FE8
			public override void OnCompleted()
			{
				this.observer.OnNext(Notification.CreateOnCompleted<T>());
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x040008D9 RID: 2265
			private readonly MaterializeObservable<T> parent;
		}
	}
}
